import { Component } from "react";

class Chapter9 extends Component {
    constructor(props) {
        super(props);
    }
    state = {
        counts: 1,
    };
    increment = (e) => {
        console.log(e);
        this.setState({
            counts: this.state.counts + 1,
        });
    };
    add = (num) => {
        return (e) => {
            console.log(e);
            this.setState({
                counts: this.state.counts + num,
            });
        };
    };
    render() {
        const { title } = this.props;
        return (
            <div className="wrapper wrapper9">
                <div className="page-header">
                    <h3>{title}</h3>
                </div>
                <div className="page-content">
                    <div className="alert alert-danger">
                        当前数值为：{this.state.counts}
                    </div>
                    <div
                        className="btn btn-primary"
                        onClick={this.increment}
                        style={{ marginRight: "10px" }}
                    >
                        增加1
                    </div>
                    <div className="btn btn-danger" onClick={this.add(2)}>
                        增加2
                    </div>
                </div>
            </div>
        );
    }
}

export default Chapter9;
